<?php 
	class Tv extends CI_Controller{
		public function __construct(){
			parent::__construct();
		}
		
		public function list_tv($str="",$id=""){
			$resultArray = array();
			$this->db->select("TVID,TVName,TVLinkIOS,pic_path");
			$this->db->where("status",1);
			if($str == "top"){
				$this->db->order_by("clickcount","DESC");
				$this->db->limit(10);
			}else if($str =="country"){
				$this->db->where("TVArea",$id);
			}else if($str =="lang"){
				$this->db->where("TVLanguage",$id);
			}else if($str == "class_type"){
				$this->db->where("TVClass",$id);
			}else if($str == "search"){
				$id = str_replace("%20", " ", $id);
				$this->db->like("TVName",$id);
			}
			$this->db->order_by("TVName","ASC");
			$res = $this->db->get("mobile_p_tv_info")->result_array();
			foreach ($res as $P){
				$tmp['TVID'] = $P['TVID'];
				$tmp['TVName'] = $P['TVName'];
				$tmp['TVLinkIOS'] = trim($P['TVLinkIOS']);
				$tmp['pic_path'] = $P['pic_path'];
				$resultArray[] = $tmp;
			}
			echo  json_encode($resultArray);
		}
		
		public function list_tv_faverite($str=""){
			$resultArray = array();
			if($str !=""){
				//$str2 = str_replace("-", ",", $str);
				$arr = explode("-", $str);
				//echo $str2;
				$this->db->select("TVID,TVName,TVLinkIOS,pic_path");
				$this->db->where("status",1);
				$this->db->where_in("TVID",$arr);
				$this->db->order_by("TVName","ASC");
				$res = $this->db->get("mobile_p_tv_info")->result_array();
				foreach ($res as $P){
					$tmp['TVID'] = $P['TVID'];
					$tmp['TVName'] = $P['TVName'];
					$tmp['TVLinkIOS'] = trim($P['TVLinkIOS']);
					$tmp['pic_path'] = $P['pic_path'];
					$resultArray[] = $tmp;
				}
			}
			echo  json_encode($resultArray);
		}
		
		public function tv_count(){
			$pkid = $this->input->post("tvid");
			$this->db->where("TVID",$pkid);
			$rows = $this->db->get("mobile_p_tv_info")->row();
			$num = $rows->clickcount;
			$num +=1;
			$this->db->where("TVID",$pkid);
			$res = $this->db->update("mobile_p_tv_info",array("clickcount"=>$num));
			if($res){
				$arrs['StatusID']  	= "1";
				$arrs['Error']			="Success";
			}else{
				$arrs['StatusID']  	= "0";
				$arrs['Error']			="Update error";
			}
			echo  json_encode($arrs);
		}
		
		public function country(){
			$this->db->order_by("name_en","ASC");
			$res = $this->db->get("mobile_p_tv_country")->result_array();
			foreach ($res as $index){
				$tmp['pkid']			=$index['pkid'];
				$tmp['name_en']	=$index['name_en'];
				$arr[] = $tmp;
			}
			echo json_encode($arr);
		}
		
		public function class_type(){
			$this->db->order_by("name_en","ASC");
			$res = $this->db->get("mobile_p_tv_class")->result_array();
			foreach ($res as $index){
				$tmp['pkid']			=$index['pkid'];
				$tmp['name_en']	=$index['name_en'];
				$arr[] = $tmp;
			}
			echo json_encode($arr);
		}
		
		public function language(){
			$this->db->order_by("name_en","ASC");
			$res = $this->db->get("mobile_p_tv_language")->result_array();
			foreach ($res as $index){
				$tmp['pkid']			=$index['pkid'];
				$tmp['name_en']	=$index['name_en'];
				$arr[] = $tmp;
			}
			echo json_encode($arr);
		}
	}